from ..extensions import db
from datetime import datetime


class ParkingSpace(db.Model):
    __tablename__ = 'parking_spaces'
    
    id = db.Column(db.BigInteger(), primary_key=True, autoincrement=True, comment='车位ID')
    location = db.Column(db.String(255), comment='车位')
    carPlate = db.Column(db.String(255), comment='绑定车辆车牌')
    user_id = db.Column(db.BigInteger(), db.ForeignKey('users.id'), comment='用户ID')
    feeValidityPeriod = db.Column(db.String(255), comment='费用有效期')
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='创建时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'location': self.location,
            'carPlate': self.carPlate,
            'feeValidityPeriod': self.feeValidityPeriod,
            'user_id': self.user_id,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None
        }